<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>人员管理</title>
<script type="text/javascript" src="${ctxStatic}/CryptoJS/components/core-min.js" charset="utf-8" ></script>
<script type="text/javascript" src="${ctxStatic}/CryptoJS/rollups/sha256.js" charset="utf-8" ></script>
<script type="text/javascript" src="${ctx}/js/password.js" charset="utf-8" ></script>
<link href="${ctx}/styles/css/password.css" type="text/css" rel="stylesheet" />
<script src="${ctx}/js/emailAutoComplete.js"></script>
<style>
/*邮箱提示框样式*/

		ul, li {
			list-style:none;
		}
		.inputElem {
			width:198px;
			height:22px;
			line-height:22px;
			border:1px solid #ccc;
		}
		.parentCls ul{ padding-left: 10px; padding-right: 10px;background-color: darkgray }
		.auto-tip li { width: 100%; height: 30px; line-height: 30px; font-size: 14px;}
		.auto-tip li.hoverBg {
			background:#ddd;
			cursor:pointer;
		}

		.hidden {
			display:none;
		}

</style>
<script type="text/javascript">
$(document).ready(function(){
	$("#category").focus();
	$("#inputForm").validate({
		rules: {
			username: {
				remote:"${ctx}/user/checkUserName.do?oldName=" + encodeURIComponent("${user.username}"),
				maxlength:12,
				minlength:3,
				loginName:true
			},
			email: {
				required: true,
				email: true,
				maxlength:100,
				remote:"${ctx}/user/checkEmail.do?oldEmail=" + encodeURIComponent("${user.email}")
				},
			sex:{required: true},
			'org.orgName':{required: true},
			name:{
				maxlength:25
			},
			mobilePhone:{
				phone:true
			},
			password:{
				loginPdcode:true
			},
			dutyName:{
				maxlength:25
			},
			remark:{
				maxlength:100
			},
			orgName:{
				maxlength:100
			}
		},
		messages: {
			username: {remote: "登录名已存在"},
			confirmNewPdcode: {equalTo: "输入与上面相同的密码"},
			email: {required: "请输入Email地址",email: "请输入正确的email地址",remote:"该邮箱已经存在"}
		},
		submitHandler:function(form){
			var username=$('#username').val();
			var pdcode=$('#password').val(); 
			if(pdcode!=''){
				pdcode= CryptoJS.SHA256(pdcode+"{"+username+"}");
				$('#password').val(pdcode);
				$('#confirmNewPdcode').val(pdcode);
			}
			form.submit();
		},
		errorContainer: "#messageBox",
		errorPlacement: function(error, element) {
			$("#messageBox").text("输入有误，请先更正。");
			if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
				error.appendTo(element.parent().parent());
			} else {
				error.insertAfter(element);
			}
		}
	});
});
</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/user/listInfo.do?top=${fns:encodeParam(top)}&left=${fns:encodeParam(left)}"> <i
				class="icon icon-list"></i>&nbsp;<span>人员列表</span>
		</a></li>
		<sec:authorize ifAnyGranted="ROLE_sys_user_edit" ></sec:authorize>
		<li class="active"><a
			href="${ctx}/user/input.do?top=${fns:encodeParam(top)}&left=${fns:encodeParam(left)}"> <i
				class="icon icon-edit"></i>&nbsp;<span>人员${not empty
				id?'修改':'添加'}</span></a></li>
	</ul>
	<form id="inputForm" action="${ctx}/user/save.do?top=${fns:encodeParam(top)}&left=${fns:encodeParam(left)}"
		method="post" class="form-horizontal autoHeight">
 		<input type="hidden" name="token" value="${token}">
		<input type="hidden" name="id" value="${user.id}" />
		<tags:message content="${msg}" />
		<fieldset>
    			<legend>人员信息</legend>
				<div class="control-group">
					<label class=" control-label">姓名<font style="color:red;">*</font>:</label>
					<div class="controls">
					  <input class=" required" id="name" name="name"
							type="text" value="${user.name}">
					</div>
				</div>
				<div class="control-group">
					<label class=" control-label">性别:</label>
					<div class="controls">
					 	<pt:code name="sex" category="1001" hasEmpty="false"  default="${user.sex}"></pt:code>
					</div>
				</div>
				<div class="control-group">
					<label class=" control-label">电话:</label>
					<div class="controls ">
						<input class="" id="mobilePhone" name="mobilePhone"
							type="text" value="${user.mobilePhone}" >
					</div>
				</div>
				<div class="control-group">
					<label class=" control-label">邮箱<font style="color:red;">*</font>:</label>
					<div class="controls parentCls">
						<input class="inputElem"  id="email" name="email"
							type="email" placeholder="test@example.com" value="${user.email}" autocomplete="off">
					</div>
				</div>
				<div class="control-group">
					<label class=" control-label">岗位职责:</label>
					<div class="controls">
						<input class="" id="dutyName" name="dutyName"
							type="text" value="${user.dutyName}">
					</div>
				</div>
				<div class="control-group">
					<label class=" control-label">所属单位 <font style="color:red;">*</font>:</label>
						<input type="hidden" name="orgId" value="${user.org.id}"/>
						<div class="controls">
						  <tags:treeselect id="office" name="org.id" value="${user.org.id}" labelName="org.orgName" labelValue="${user.org.orgName}"
								title="单位" url="/organization/treeData.do" allowClear="true"/>
						</div>
				</div>
				<div class="control-group">
					<label class=" control-label">备注:</label>
					<div class="controls">
						<input class="" id="remark" name="remark"
							type="text" value="${user.remark}">
					</div>
				</div>
		</fieldset>
		<fieldset>
   			<legend>登录授权</legend>
   			<div class="control-group">
	   			<label class=" control-label">登录名<font style="color:red;">*</font>:</label>
				<div class="controls">
					<input  id="username" name="username" class=" required"  type="text" value="${user.username}">
						<br/>
						<br/>
					<span>(只能包含中文字、英文字母、数字和下划线,3~12位)</span>
				</div>
			</div>
			<div class="control-group">
	   			<label class=" control-label">登录密码 ${fn:length(user.id) gt 0?'' : '<font style="color:red;">*</font>'}:</label>
	   			
				<div class="controls">
					<input  id="password" name="password" ${fn:length(user.id) gt 0?'' : 'class="required"'} type="password" value="" >
					<input type="hidden" name="pwd" value="${user.password}"/>
						<br/>
						<br/>
					<span>(密码必须包含大写字母、小写字母、数字,长度在6~12位之间)</span>
					<br/>
					<br/>
					<div id="level" class="pw-strength">
						<div class="pw-bar"></div>
						<div class="pw-bar-on"></div>
						<div class="pw-txt">
							<span>弱</span>
							<span>中</span>
							<span>强</span>
						</div>
					</div>
				</div>
				
			</div>
			<div class="control-group">
	   			<label class=" control-label">重复密码 ${fn:length(user.id) gt 0?'' : '<font style="color:red;">*</font>'}:</label>
				<div class="controls">
					<input  id="confirmNewPdcode" name="confirmNewPdcode" ${fn:length(user.id) gt 0?'' : 'class="required"'}
						type="password" value="" equalTo="#password">
				</div>
			</div>
			<div class="control-group">
	   			<label class=" control-label">账号管理:</label>
				<div class="controls">
					<label class="checkbox-inline">
					  <input type="checkbox" name="enable" id="enable" value="1" ${(user.enable=='1')?'checked':''}> 启用
					</label>
					<label class="checkbox-inline">
					  <input type="checkbox" name="expired" id="expired" value="1" ${(user.expired=='1')?'checked':''}> 账户过期
					</label>
					<label class="checkbox-inline">
					  <input type="checkbox" name="locked" id="locked" value="1" ${(user.locked=='1')?'checked':''}> 锁定
					</label>
					<label class="checkbox-inline">
					  <input type="checkbox" name="credexpired" id="credexpired" value="1" ${(user.credexpired=='1')?'checked':''}> 密码过期
					</label>
				</div>
			</div>
			<div class="control-group">
	   			<label class=" control-label">角色:</label>
				<div class="controls">
					<c:forEach items="${allRoles}" var="item">
						<c:choose>
						 	<c:when test="${item.roleName=='ssjrole' or  item.roleName=='xqjrole'}">
						 		<label class="radio-inline">
						 			 <input type="radio" name="roleIdList" id="${item.id}" value="${item.id}" 
						                    ${(fn:contains(user.roleIds,item.id)==true) or empty user.roleIds ?'checked':''}> ${item.roleDesc}
								</label>
						 	</c:when>
						 	<c:when test="${item.roleName=='aqrole' or  item.roleName=='sjrole' or  item.roleName=='administrator'}">
						 		<label class="radio-inline">
						 			 <input type="radio" name="roles" id="${item.id}" value="${item.id}" 
						                    ${(fn:contains(user.roleIds,item.id)==true) ?'checked':''}> ${item.roleDesc}
								</label>
						 	</c:when>
						 	<c:otherwise>
						 		<label class="checkbox-inline">
						 		<input type="checkbox" name="roleIdList" id="${item.id}" value="${item.id}" 
						                    ${fn:contains(user.roleIds,item.id)==true?'checked':''}> ${item.roleDesc}
								</label>
						 	</c:otherwise>
						</c:choose>
					</c:forEach>
				</div>
			</div>
   	    </fieldset>
		<div class="form-actions">
		  <sec:authorize ifAnyGranted="ROLE_sys_user_edit" ></sec:authorize>
				<input id="btnSubmit" class="btn btn-primary" type="submit"
					value="保 存" />
					&nbsp; <input id="btnCancel" class="btn"
					type="button" value="返 回" onclick="toBack()" />
		</div>
	</form>
</body>
</html>